/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#ifndef __PQ_BoidController_H__
#define __PQ_BoidController_H__

#include "Boid.h"

namespace PQClient
{

	class BoidController
	{
	public:
		BoidController(Boid* boid);

		~BoidController( );

		void setPosition( float x, float y, float z );
		void setReqSpeed( float speed );
		
		// Callback function used to call behaviour functions.
		static void updateFlyer(BoidController* flyer );

		void update(float deltaT);

		// The main boid behavior functions.
		void directToBoid( );
		void velocityMatching( );
		void collisionAvoidance( );
		void landscapeAvoidance( );
		void landCollisionAvoidance(float distance );
		

		void wrapAround(float *x, float *y, float *z );
		void moveObject(float deltaT);
		void convertVector( float *xi, float *yi, float *zi );
		void maintainHeadings( float *horiz, float *vert );
		void updateVelocity( double timeSpan );

		Ogre::Vector3 calculateOffset( float distance,float hAngle, float vAngle );
		Ogre::Vector3 calculateClearance( float distance, float hAngle );

		void updateWing();
		void setOrientation( float x, float y, float z );
		void setReqVelocity( float sp, float horiz, float vert );
		float getSize( );

	protected:
		Boid* _boid;

		static std::vector<BoidController *> _boidControllers;

		Ogre::ColourValue _color;
		Ogre::Real _size;

		// Position and velocity vectors.
		Ogre::Vector3 _pos;// x, y, z; of the boid
		
		Ogre::Real _speed;
		Ogre::Real _reqSpeed;
		Ogre::Vector2 _heading;
		Ogre::Vector2 _reqHeading;
	};

}

#endif
